<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fmtt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set value="${pageContext.request.contextPath}" var="path"></c:set>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <script type="text/javascript" src="/myhouse/static/manager/js/jquery-3.2.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/myhouse/static/manager/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="/myhouse/static/manager/css/main.css"/>
    <script type="text/javascript" src="/myhouse/static/manager/js/libs/modernizr.min.js"></script>
</head>
<body>
<jsp:include page="/inc/managerHead.jsp"></jsp:include>
<div class="container clearfix">
    <jsp:include page="/inc/managerLeft.jsp"></jsp:include>
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="/myhouse/manager/index">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">中介管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                    <table class="search-tab">
                        <tr>
                            <th width="70">添加房间:</th>
                            <td><input class="common-text" name="roomNum"  type="text" id="num"></td>
                            <td><input class="btn btn-primary btn2"  value="添加" type="button" id="sss"></td>
                        </tr>
                    </table>
                <span id="span"></span>
            </div>
        </div>
        <script type="text/javascript">
            $(function (){
                $("#sss").click(mediatorByName);
            });
            function mediatorByName(){
                var num = $("#num").val();
                if ( num != ""){
                   $.ajax({
                       url:"/myhouse/manager/selectBynum",
                       type:"get",
                       data:{"roomNum":num},
                       success:function (mes){
                            if (mes == "1"){
                                $.ajax({
                                    url: "/myhouse/manager/AddRoom",
                                    type: "get",
                                    data: {"roomNum":num},
                                    success:function (){
                                        location.href="/myhouse/manager/AddRoom";
                                    }
                                })
                            }else {
                                $("#span").text("房间数量重复");
                                $("#span").css("color","red");

                            }
                       }
                   })
                }
            }
        </script>

        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th>id</th>
                            <th>卧室数量</th>
                            <th>操作</th>
                        </tr>
                        <c:forEach items="${requestScope.roomList}" var="room">
                        <tr>
                               <td>${room.id}</td>
                               <td class="roomNum">${room.roomNum}间卧室</td>
                            <td onclick="sc(this)" style="color: #0a53be">删除</td>
                        </tr>
                        </c:forEach>
                    </table>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript">

        function sc(a){
            var bool = window.confirm("确定删除吗？");
            var id = $(a).parent().find('td:first').text();
            if (bool){
                $.ajax({
                    url:"/myhouse/manager/deleteRoom",
                    type:"get",
                    data:{
                        id:id
                    },
                    success:function (mes){
                        location.href="/myhouse/manager/AddRoom";
                    }
                })
            }
        }
    </script>
</div>
</body>
</html>